<template>
    <div class="box" :style="{height: height + 'px'}">
        <aitem v-if="article" :msg="article[0]" margin="0" height="3.16rem"/>
        <imp v-if="msgs" :msg="msgs[0]"/>
        <div class="s_box" v-if="msgs">
            <Sitem v-for="msg in msgs[1]" :msg="msg" :key="msg.title"/>
        </div>
        <div id="week" v-if="msgs">
            <div>一周排行</div>
            <router-link class="witem" v-for="(e, i) in msgs[2]" :to="e.href" :key="e.title" tag="div">{{i + 1}} {{e.title}}</router-link>
        </div>
        <div class="s_box" style="border: none" v-if="msgs">
            <Sitem v-for="msg in msgs[3]" :msg="msg" :key="msg.img"/>
        </div>
        <div class="ad"></div>
        <div class="s_box" style="border: none" v-if="msgs">
            <Sitem v-for="msg in msgs[4]" :msg="msg" :key="msg.img"/>
        </div>
        <aitem v-if="article" :msg="article[1]" :hot="true" margin="0.3rem 0.3rem 0"/>
        <div class="s_box" style="border: none" v-if="msgs">
            <Sitem v-for="msg in msgs[5]" :msg="msg" :key="msg.img"/>
        </div>
        <Footer state="1"></Footer>
    </div>
</template>
<script>
import aitem from "../public/Aitem"
import imp from "../public/Imp"
import Sitem from "../public/Sitem"
import Footer from "../public/Footer"
import { Get, Post, Port } from "../../../server/ajax"
export default {
    data () {
        return {
            height: document.body.clientHeight - parseFloat(window.getComputedStyle(document.documentElement)["fontSize"]) * 1.01,
            article: null,
            msgs: null
        }
    },
    components: {
        aitem,
        imp,
        Sitem,
        Footer
    },
    mounted() {
    this.$el.addEventListener("scroll", function(){
        if(this.$el.scrollTop == 0){
            this.$parent.$parent.tState = 1
            this.$parent.$parent.updata()
        }
    }.bind(this))
    Post(`${Port}/mobile/cms/subjects`, {
      page_size: 2
    }, function(data) {
      this.article = data
    }.bind(this))
    Post(`${Port}/mobile/cms/news`, {
      page_size: 18,
      cid: 109
    }, function(data){
      this.msgs = data
      var all = new Array(Math.ceil(data.length / 3))
      data.forEach((e, i)=> {
        var index = Math.floor(i  / 3)
        if(typeof(all[index]) == 'undefined'){
            all[index] = []
        }
        all[index].push(e)
      })
      this.msgs = all
    }.bind(this))
  }
};
</script>
<style scoped>
.box{
    overflow: auto;
}
.s_box{
    padding: 0 0.3rem;
    border-top: 0.2rem solid #f4f5f7;
}
#week{
    position: relative;
    width: 6.9rem;
    height: 3rem;
    background-size: cover;
    background-position: center center;
    background-image: url('../../assets/news/week.png');
    font-size: 0.32rem;
    color: #fff;
    margin: 0.2rem auto 0;
    padding-top: 0.7rem;
}
#week>div:nth-child(1){
    position: absolute;
    top: 0;
    left: 0;
    width: 1.4rem;
    height: 0.5rem;
    font-size: 0.28rem;
    line-height: 0.5rem;
    text-align: center;
    background-size: cover;
    background-image: url('../../assets/news/w_bg.png');
}
.witem{
    margin-bottom: 0.34rem;
    padding: 0 0.3rem;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}
.ad{
    width: 6.92rem;
    height: 3rem;
    background-image: url('~@/assets/article/ad.png');
    background-size: cover;
    margin: 0.25rem auto 0;
}
</style>